In [1]:
from path_helpers import path
from droplet_planning import svg_polygons_to_df
from dmf_device_ui.tesselate import tesselate_shapes_frame
from dmf_device_ui.plot import plot_shapes
from dmf_device_ui.point_query import get_shapes_pymunk_space
from dmf_device_ui.device import ShapesCanvas
import pandas as pd
import matplotlib.pyplot as plt

%matplotlib inline


Loading chipmunk for Windows (32bit) [C:\Users\Christian\Documents\microdrop-1.0\python-2.7.9\lib\site-packages\pymunk\chipmunk.dll]

Load device SVG


In [2]:
drawing_shape = pd.Series([1920, 1080], index=['width', 'height'])
device_svg = 'static/device.svg'

device_canvas = ShapesCanvas.from_svg(device_svg, padding_factor=0.1, canvas_shape=drawing_shape)

Scale and center SVG points to drawing shape


In [3]:
svg_shape = device_canvas.source_shape

svg_axis = device_canvas.df_shapes[['x', 'y']].plot(kind='scatter', x='x', y='y',
                                                    xlim=(0, svg_shape.width),
                                                    ylim=(0, svg_shape.height))                                          
drawing_axis = (device_canvas.df_canvas_shapes[['x', 'y']]
                .plot(kind='scatter', x='x', y='y',
                      xlim=(0, device_canvas.canvas_shape.width),
                      ylim=(0, device_canvas.canvas_shape.height)))
svg_axis.set_aspect(True)
drawing_axis.set_aspect(True)


Get x/y-offset and scale for later use


In [4]:
device_canvas.canvas_offset, device_canvas.canvas_scale


Out[4]:
(x    521.769083
 y    108.000000
 dtype: float64, 1.7808903784058139)

Tesselate scaled shapes into convex shapes and construct pymunk Space

Draw tesselations in drawing layout


In [5]:
axis = plot_shapes(device_canvas.df_canvas_tesselations, ['path_id', 'triangle_i'],
                   fc='none')
plot_shapes(device_canvas.df_canvas_shapes, ['path_id'], alpha=.3, axis=axis)
axis.set_aspect(True)
axis.set_xlim(0, device_canvas.canvas_shape.width)
axis.set_ylim(0, device_canvas.canvas_shape.height)
pass


Demonstrate electrode lookup based on drawing coordinates


In [6]:
device_canvas.find_shape(1000, 480)


Out[6]:
'electrode69'